import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smart_ai_dart/consts/index.dart';
import 'package:smart_ai_dart/utils/themes.dart';
import 'package:smart_ai_dart/widgets/load_image/index.dart';

class StateWidget extends StatelessWidget {
  const StateWidget({super.key, required this.type, this.hintText});

  final StateType type;
  final String? hintText;

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        if (type == StateType.loading)
          const CupertinoActivityIndicator(radius: 16.0)
        else if (type != StateType.empty)
          Opacity(
            opacity: context.isDark ? 0.5 : 1,
            child: LoadAssetImage(
              'state/${type.img}',
              width: 120,
            ),
          ),
        const SizedBox(
          width: double.infinity,
          height: Sizes.gap_dp16,
        ),
        Text(
          hintText ?? type.hintText,
          style: Theme.of(context)
              .textTheme
              .titleSmall
              ?.copyWith(fontSize: Sizes.font_sp14),
        ),
        Gaps.vGap50,
      ],
    );
  }
}

enum StateType {
  /// 订单
  order,

  /// 商品
  goods,

  /// 无网络
  network,

  /// 消息
  message,

  /// 无提现账号
  account,

  /// 空
  empty,

  /// 加载中
  loading,
}

extension StateTypeExtension on StateType {
  String get img =>
      <String>['zwdd', 'zwsp', 'zwwl', 'zwxx', 'zwzh', '', ''][index];

  String get hintText => <String>[
        'state_type.order_empty'.tr,
        'state_type.goods_empty'.tr,
        'state_type.network_error'.tr,
        'state_type.message_empty'.tr,
        'state_type.account_empty'.tr,
        '',
        ''
      ][index];
}
